package com.gxa.autoparts.portal.controller;

import com.gxa.autoparts.core.common.JsonResult;
import com.gxa.autoparts.core.pojo.Article;
import com.gxa.autoparts.portal.service.ArticleService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author R
 * @data 2022-01-06 14:32
 */
@RestController
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    ArticleService service;

    @PostMapping("/getArticles")
    @ApiOperation("查找文章接口")
    @ApiImplicitParam(name = "title",value = "查询的文章的标题",required = true,paramType = "query",dataType = "String")
    public Map getArticles(String title){
        List<Article> articles = service.selectByTitle(title);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(articles);
        return jsonResult.getDataMap();
    }

    @PostMapping("/selectById")
    @ApiOperation("通过id找文章的详情信息")
    @ApiImplicitParam(name = "id",value = "需要查看详情的文章id",paramType = "query",dataType = "Long",required = true)
    public Map selectById(Long id){
        Article article = service.selectById(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(article);
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        return jsonResult.getDataMap();
    }
}
